/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "subject")
@NamedQueries({@NamedQuery(name = "Subject.findByCode", query = "SELECT s FROM Subject s WHERE s.code = :code"), @NamedQuery(name = "Subject.findByTitle", query = "SELECT s FROM Subject s WHERE s.title = :title")})
public class Subject implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "code", nullable = false)
    private String code;
    @Column(name = "title", nullable = false)
    private String title;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "subject1")
    private Collection<Course> courseCollection;

    public Subject() {
    }

    public Subject(String code) {
        this.code = code;
    }

    public Subject(String code, String title) {
        this.code = code;
        this.title = title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Collection<Course> getCourseCollection() {
        return courseCollection;
    }

    public void setCourseCollection(Collection<Course> courseCollection) {
        this.courseCollection = courseCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (code != null ? code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Subject)) {
            return false;
        }
        Subject other = (Subject) object;
        if ((this.code == null && other.code != null) || (this.code != null && !this.code.equals(other.code))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.Subject[code=" + code + "]";
    }

}
